package org.lex.ftp.ui;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class StatusPane extends JPanel implements StatusBar {
	private static int MaxProgressValue = 100;
	// ========================================
	private JProgressBar progressBar = null;
	private JLabel statusLabel = null;
	private JPanel progressPane = null;
	private JLabel percentLabel = null;
	private JLabel elapsedTimeLabel = null;
	private JLabel remainedTimeLabel = null;

	public StatusPane() {
		super();
		initialize();
		this.clear();
	}

	public void setStatusString(String status) {
		this.statusLabel.setText(status);
	}

	public void setProgressString(String string) {
		this.getProgressBar().setString(string);
	}

	public void setPercent(int percent) {
		this.percentLabel.setText(percent + "%");
		this.getProgressBar().setValue(percent);
	}

	public void setElapsedTime(String time) {
		this.elapsedTimeLabel.setText("Elapsed: " + time);
	}

	public void setRemainedTime(String time) {
		this.remainedTimeLabel.setText("Remaining: " + time);
	}

	public void clear() {
		this.setProgressString("");
		this.setPercent(0);
		this.setElapsedTime("");
		this.setRemainedTime("");
	}

	// =======================
	private void initialize() {
		statusLabel = new JLabel();
		statusLabel.setText("Status");
		this.setLayout(new BorderLayout());
		this.setSize(500, 30);
		this.add(statusLabel, java.awt.BorderLayout.WEST);
		this.add(getProgressPane(), java.awt.BorderLayout.EAST);
		this.clear();
	}

	private JPanel getProgressPane() {
		if (progressPane == null) {
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.insets = new java.awt.Insets(0, 1, 0, 5);
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.insets = new java.awt.Insets(0, 1, 0, 0);
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.insets = new java.awt.Insets(0, 1, 0, 0);
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
			gridBagConstraints.weightx = 1.0;
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints.ipadx = 80;
			remainedTimeLabel = new JLabel();
			remainedTimeLabel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.SoftBevelBorder.LOWERED));
			remainedTimeLabel.setText("Remaining: 00:00:00");
			elapsedTimeLabel = new JLabel();
			elapsedTimeLabel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.SoftBevelBorder.LOWERED));
			elapsedTimeLabel.setText("Elapsed: 00:00");
			percentLabel = new JLabel();
			percentLabel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.SoftBevelBorder.LOWERED));
			percentLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			percentLabel.setText("%0");
			progressPane = new JPanel();
			progressPane.setLayout(new GridBagLayout());
			progressPane.add(getProgressBar(), gridBagConstraints);
			progressPane.add(percentLabel, gridBagConstraints1);
			progressPane.add(elapsedTimeLabel, gridBagConstraints2);
			progressPane.add(remainedTimeLabel, gridBagConstraints3);
		}
		return progressPane;
	}

	private JProgressBar getProgressBar() {
		if (null == this.progressBar) {
			progressBar = new JProgressBar(0, MaxProgressValue);
			progressBar.setStringPainted(true);
		}
		return progressBar;
	}
}
